//
//  PayMoneyCountViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/3.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "PayMoneyCountViewController.h"
#import "BankVeriftyViewController.h"
#import "FastPaymentViewController.h"

@interface PayMoneyCountViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>{
    NSInteger _bankIndex;   // 银行选择 记录
}

@property (nonatomic, weak)UIImageView * backImageView;

@property (nonatomic, weak)UIImageView * warnImage;

@property (nonatomic, weak)UILabel * warnningLabel;

@property (nonatomic, weak)UIView * topView;

@property (nonatomic, weak)UILabel * quickChooseLabel;

@property (nonatomic, weak)UIButton * minButton;

@property (nonatomic, weak)UIButton * middleButton;

@property (nonatomic, weak)UIButton * maxButton;

@property (nonatomic, weak)UILabel * payMoneyCountLabel;

@property (nonatomic, weak)UITextField * payMoneyText;

@property (nonatomic, weak)UILabel * explationLabel;

@property (nonatomic, weak)UIView * lineView;

@property (nonatomic, weak)UIButton * payButton;
//===========
@property (nonatomic, weak)UILabel * oneDoller;
@property (nonatomic, weak)UILabel * payMoney;
@property (nonatomic, weak)UIView * alineView;
@property (nonatomic, weak)UILabel * aExplationLabel;

@property (nonatomic, weak)UILabel * bankLabel;
@property (nonatomic, weak)UIImageView * logoImageView;

@end

@implementation PayMoneyCountViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupNavBar];
    [self setupUI];
    [self loadData];
}



- (void)loadData{
    //site/exchange-mode
    [[NetworkTool sharedTools] POST:@"site/exchange-mode" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSDictionary * dict = responseObject[@"param"];
        
        float exchange = [dict[@"exchange"] floatValue];
        float payMoney = exchange * 500;
        
        self.oneDoller.text = [NSString stringWithFormat:@"1USD = %.4f人民币(今日汇率)",exchange];
        self.payMoney.text = [NSString stringWithFormat:@"应付总额:￥%.2f",payMoney];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
    
}



- (void)setupNavBar{
    
    self.title = @"入金";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToAccountView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}



- (void)setupUI{
    
    self.view.backgroundColor = [UIColor whiteColor];

    
    UIImageView * backImage = [[UIImageView alloc] init];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    
    self.backImageView = backImage;
    
    [self.view addSubview:self.backImageView];
    
    
    UIView * topView = [UIView new];
    
    topView.backgroundColor = ColorWithRGB(0x0a1a21);
    
    topView.layer.cornerRadius = 5 * SCREENH6;
    topView.userInteractionEnabled = YES;
    topView.layer.masksToBounds = YES;
    topView.layer.borderColor = [ColorWithRGB(0x102b38) CGColor];
    topView.layer.borderWidth = 1 * SCREENH6;
    
    self.topView = topView;
    
    [self.view addSubview:self.topView];
    

    UIImageView * warnImage = [UIImageView new];
    
    warnImage.image = [UIImage imageNamed:@"提示"];
    warnImage.hidden = YES;
    
    self.warnImage = warnImage;
    
    
    [self.view addSubview:self.warnImage];
    
    
    UILabel * warnningLabel = [UILabel new];
    
    warnningLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    warnningLabel.textColor = ColorWithRGB(0xfc4f79);
    warnningLabel.text = @"手机支付单笔最高限额$1400,每日累计额度$3500";
    
    self.warnningLabel = warnningLabel;
    
    self.warnningLabel.hidden = YES;
    
    [self.view addSubview:self.warnningLabel];
    
   
    UILabel * quickChooseLabel = [UILabel new];
    
    quickChooseLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    quickChooseLabel.textColor = ColorWithRGB(0xc8c8c8);
    quickChooseLabel.text = @"快速选择";
    
    self.quickChooseLabel = quickChooseLabel;
    
    [self.view addSubview:self.quickChooseLabel];
    
    
    UIButton * minButton = [[UIButton alloc] init];
    
    [minButton setTitle:@"$500" forState:UIControlStateNormal];
    minButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:16 * SCREENH6];
    minButton.layer.borderColor = [ColorWithRGB(0x3dba8a) CGColor];
    //边框宽度
        minButton.layer.borderWidth =1.0f;
    //处理圆角
    minButton.layer.cornerRadius =3.0f;
    [minButton setTitleColor:ColorWithRGB(0x3dba8a) forState:UIControlStateNormal];
    [minButton addTarget:self action:@selector(didMoneyButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.minButton = minButton;
    
    [self.view addSubview:self.minButton];
    
    
    UIButton * middleButton = [[UIButton alloc] init];
    
    [middleButton setTitle:@"$1000" forState:UIControlStateNormal];
    middleButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:16 * SCREENH6];
    middleButton.layer.borderColor = [ColorWithRGB(0x3dba8a) CGColor];
    //边框宽度
    middleButton.layer.borderWidth =1.0f;
    //处理圆角
    middleButton.layer.cornerRadius =3.0f;
    [middleButton setTitleColor:ColorWithRGB(0x3dba8a) forState:UIControlStateNormal];
    [middleButton addTarget:self action:@selector(didMoneyButton:) forControlEvents:UIControlEventTouchUpInside];
    middleButton.hidden = YES;
    
    self.middleButton = middleButton;
    
    [self.view addSubview:self.middleButton];
    
    
    UIButton * maxButton = [[UIButton alloc] init];
    
    [maxButton setTitle:@"$1500" forState:UIControlStateNormal];
    maxButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:16 * SCREENH6];
    maxButton.layer.borderColor = [ColorWithRGB(0x3dba8a) CGColor];
    //边框宽度
    maxButton.layer.borderWidth =1.0f;
    //处理圆角
    maxButton.layer.cornerRadius =3.0f;
    [maxButton setTitleColor:ColorWithRGB(0x3dba8a) forState:UIControlStateNormal];
    [maxButton addTarget:self action:@selector(didMoneyButton:) forControlEvents:UIControlEventTouchUpInside];
    maxButton.hidden = YES;
    
    self.maxButton = maxButton;
    
    [self.view addSubview:self.maxButton];
    //payMoneyCountLabel
    
    UILabel * payMoneyCountLabel = [UILabel new];
    
    payMoneyCountLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    payMoneyCountLabel.textColor = ColorWithRGB(0xc8c8c8);
    payMoneyCountLabel.text = @"充值金额";
    payMoneyCountLabel.hidden = YES;
    
    self.payMoneyCountLabel = payMoneyCountLabel;
    
    
    
    [self.view addSubview:self.payMoneyCountLabel];
    
    
    UITextField * payMoneyText = [[UITextField alloc] init];
    
    payMoneyText.borderStyle = UITextBorderStyleLine;
    payMoneyText.backgroundColor = ColorWithRGB(0x0a1a21);
    payMoneyText.layer.borderWidth = 1.0 * SCREENH6;
    payMoneyText.layer.borderColor = [ColorWithRGB(0x102b38) CGColor];
    
    //设置光标颜色
    payMoneyText.tintColor = ColorWithRGB(0x686868);
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = ColorWithRGB(0x686868);
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    payMoneyText.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"   最小100美金" attributes:attrs];
    payMoneyText.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    payMoneyText.textColor = ColorWithRGB(0x686868);
    payMoneyText.keyboardType = UIKeyboardTypeDecimalPad;
    payMoneyText.keyboardAppearance = UIKeyboardAppearanceAlert;
    payMoneyText.hidden = YES;
    
    self.payMoneyText = payMoneyText;
    
    [self.view addSubview:self.payMoneyText];
    
    
    UILabel * explationLabel = [UILabel new];
    
    explationLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    explationLabel.textColor = ColorWithRGB(0x3bb486);
    explationLabel.text = @"当前汇率6.8666，折合人民币681.67";
    
    self.explationLabel = explationLabel;
    self.explationLabel.hidden = YES;
    
    [self.view addSubview:self.explationLabel];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = [UIColor whiteColor];
    lineView.alpha = 0.1;
    lineView.hidden = YES;
    
    self.lineView = lineView;
    
    [self.view addSubview:self.lineView];

    
    UIButton * payButton = [[UIButton alloc] init];
    
    [payButton setTitle:@"去支付" forState:UIControlStateNormal];
    payButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:17 * SCREENH6];//
    [payButton setBackgroundImage:[UIImage imageNamed:@"注册"] forState:UIControlStateNormal];
    payButton.layer.borderColor = [[UIColor blackColor] CGColor];
    //边框宽度
    payButton.layer.borderWidth =1.0f;
    //处理圆角
    payButton.layer.cornerRadius =5.0f;
    [payButton setTitleColor:ColorWithRGB(0xffffff) forState:UIControlStateNormal];
    [payButton addTarget:self action:@selector(didNextButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.payButton = payButton;
    
    [self.view addSubview:self.payButton];

    
    //========================
    UILabel * oneDoller = [UILabel new];
    
    oneDoller.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    oneDoller.textColor = ColorWithRGB(0xc8c8c8);
    oneDoller.text = @"1USD = 6.6876人民币(中国银行当前现汇卖出价)";
    
    self.oneDoller = oneDoller;
    
    [self.view addSubview:self.oneDoller];
    
    
    UILabel * payMoney = [UILabel new];
    
    payMoney.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    payMoney.textColor = ColorWithRGB(0xc8c8c8);
    payMoney.text = @"应付总额：￥3343.80";
    
    self.payMoney = payMoney;
    
    [self.view addSubview:self.payMoney];
    
    
    UIView * alineView = [UIView new];
    
    alineView.backgroundColor = [UIColor whiteColor];
    alineView.alpha = 0.1;
    
    self.alineView = alineView;
    
    [self.view addSubview:self.alineView];
    
    
    UILabel * newExplationLabel = [UILabel new];
    
    newExplationLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:13 * SCREENH6];
    newExplationLabel.textColor = ColorWithRGB(0xc8c8c8);
    newExplationLabel.numberOfLines = 0;
    newExplationLabel.text = @"您好！您即将报名由We-Link微链金服(以下简称“微链”)联合DCM Group共同举办的《我是交易者》实盘交易大赛，本次大赛参赛资格500USD，活动结束7个工作日内科申请出金。";
    
    self.aExplationLabel = newExplationLabel;
    
    [self.view addSubview:self.aExplationLabel];
    
    
    UILabel * bankLabel = [UILabel new];
    
    bankLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:13 * SCREENH6];
    bankLabel.textColor = ColorWithRGB(0xc8c8c8);
    bankLabel.text = @"暂支持以下银行:";
    
    self.bankLabel = bankLabel;
    
    [self.view addSubview:self.bankLabel];
    
    
    UIImageView * logoImageView = [UIImageView new];
    
    logoImageView.image = [UIImage imageNamed:@"bank-0"];
    logoImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.logoImageView = logoImageView;
    
    
    [self.view addSubview:self.logoImageView];
}



- (void)viewDidLayoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.view);
    }];
    //31 * 27
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(45 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(64 * SCREENH6);
    }];
    
    
    [self.warnImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(72 * SCREENH6);
        make.width.mas_equalTo(31 * SCREENH6);
        make.height.mas_equalTo(27 * SCREENH6);
    }];
    
    [self.warnningLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.warnImage.mas_trailing).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.warnImage);
    }];
    
    [self.quickChooseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.topView.mas_bottom).offset(20 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(72 * SCREENH6);
        make.leading.mas_equalTo(self.warnImage);
    }];
    
    [self.minButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.quickChooseLabel);
        make.top.mas_equalTo(self.quickChooseLabel.mas_bottom).offset(10 * SCREENH6);
        make.width.mas_equalTo(100 * SCREENH6);
        make.height.mas_equalTo(55 * SCREENH6);
    }];
    
    
    [self.middleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.mas_equalTo(self.minButton);
//        make.leading.mas_equalTo(self.minButton.mas_trailing).offset(20 * SCREENH6);
        make.centerX.mas_equalTo(self.view);
    }];
    
    [self.maxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.mas_equalTo(self.middleButton);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
    }];
    
    [self.payMoneyCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.minButton.mas_bottom).offset(70 * SCREENH6);
        make.leading.mas_equalTo(self.minButton);
    }];
 
    [self.payMoneyText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.payMoneyCountLabel);
        make.leading.mas_equalTo(self.payMoneyCountLabel.mas_trailing).offset(8 * SCREENH6);
        make.height.mas_equalTo(55 * SCREENH6);
        make.width.mas_equalTo(273 * SCREENH6);
    }];
    
    [self.explationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.payMoneyText);
        make.top.mas_equalTo(self.payMoneyText.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.top.mas_equalTo(self.explationLabel.mas_bottom).offset(23 * SCREENH6);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
    
    
    //=============
    
    [self.oneDoller mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.minButton);
        make.top.mas_equalTo(self.minButton.mas_bottom).offset(30 * SCREENH6);
    }];
    
    [self.payMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneDoller);
        make.top.mas_equalTo(self.oneDoller.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.alineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.lineView);
        make.top.mas_equalTo(self.payMoney.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.aExplationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.alineView.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.bankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.aExplationLabel);
        make.top.mas_equalTo(self.aExplationLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.height.mas_equalTo(195 * SCREENH6);
        make.top.mas_equalTo(self.bankLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.payButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(20 * SCREENH6);
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.height.mas_equalTo(55 * SCREENH6);
    }];
}



//点击快速按钮，500，1000，1500
- (void)didMoneyButton:(UIButton *)button{
    
    if (button == self.minButton) {
        
        self.payMoneyText.text = @"500";
    }else if (button == self.middleButton){
        
        self.payMoneyText.text = @"1000";
    }else{
        
        self.payMoneyText.text = @"1500";
    }
    
}



- (void)didNextButton{
    
//    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    //self.payMoneyText.text
//    NSDictionary * parameters = @{@"amount":@"500",@"bankId":self.bankID};
//    
//    [[NetworkTool sharedTools] POST:@"pay/yl" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
//        
//        NSString * code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
//        
//        NSDictionary * paramDict = responseObject[@"param"];
//        
//        if ([code isEqualToString:@"1000"]) {
//            
//            self.hidesBottomBarWhenPushed = YES;
//            
//            BankVeriftyViewController * bankVeriftyVC = [BankVeriftyViewController new];
//            
//            bankVeriftyVC.payNo = [NSString stringWithFormat:@"%@",paramDict[@"jobId"]];
//            bankVeriftyVC.orderNo = [NSString stringWithFormat:@"%@",paramDict[@"orderNo"]];
//            bankVeriftyVC.orderCode = [NSString stringWithFormat:@"%@",paramDict[@"orderId"]];
//            
//            [self.navigationController pushViewController:bankVeriftyVC animated:YES];
//            [MBProgressHUD hideHUDForView:self.view animated:YES];
//        }else if ([code isEqualToString:@"0"]){
//            
//            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
//                                                                           message:@"恭喜你，支付成功！"
//                                                                    preferredStyle:UIAlertControllerStyleAlert];
//            
//            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
//                                                                  handler:^(UIAlertAction * action) {
//                                                                      //响应事件
//                                                                      [self.navigationController popViewControllerAnimated:YES];
//                                                                  }];
//            
//            [alert addAction:defaultAction];
//            [self presentViewController:alert animated:YES completion:nil];
//            [MBProgressHUD hideHUDForView:self.view animated:YES];
//            
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"loadUserInfo" object:nil];
//        }else{
//            
//            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
//                                                                           message:responseObject[@"msg"]
//                                                                    preferredStyle:UIAlertControllerStyleAlert];
//            
//            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
//                                                                  handler:^(UIAlertAction * action) {
//                                                                      //响应事件
//                                                                      
//                                                                  }];
//            
//            [alert addAction:defaultAction];
//            [self presentViewController:alert animated:YES completion:nil];
//            [MBProgressHUD hideHUDForView:self.view animated:YES];
//        }
//        
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        
//        NSLog(@"%@",error);
//    }];
    
    FastPaymentViewController * fastVC = [FastPaymentViewController new];
    
    [self.navigationController pushViewController:fastVC animated:YES];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
     [self.payMoneyText resignFirstResponder];
}


- (void)backToAccountView{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
